package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.entity.WmNews;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmNewsService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author Mr_Su
 * @since 2022-06-28
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController{

    @Autowired
    private IWmNewsService wmNewsService;

    @PostMapping("/list")
    @ApiOperation(value = "listByCondition",notes = "分页带条件查询自媒体文章列表")
    @ApiModelProperty(name = "dto",dataType = "WmNewsPageDto",required = true)
    public ResponseResult listByCondition(@RequestBody WmNewsPageDto dto){
        return wmNewsService.listByCondition(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "getById",notes = "根据id获取文章信息")
    @ApiModelProperty(name = "id",dataType = "Integer",required = true)
    public ResponseResult getById(@PathVariable("id") Integer id) {
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
        return wmNewsService.submit(dto);
    }

    @PutMapping("/down_or_up")
    @ApiOperation(value = "upOrDown",notes = "自媒体端-文章上下架")
    @ApiModelProperty(name = "dto",dataType = "WmNewsDto",required = true)
    public ResponseResult upOrDown(@RequestBody WmNewsDto dto){
        return wmNewsService.upOrDown(dto);
    }

}
